﻿@page
@model Chino.IdentityServer.Pages.Dashboard.IdentityResourcesModel
@inject IStringLocalizer<Chino.IdentityServer.Pages.Dashboard.IdentityResourcesModel> L
@{
    Layout = "_DashboardLayout";
    ViewData["pageName"] = "identityResources";

    var thisUrl = string.IsNullOrEmpty(Request.Path) ? "~/" : $"~{Request.Path.Value}";
}


<div class="mt-3 container">
    <div class="row">
        <div class="col-md-12">
            <div>
                @*搜索框*@
                <form method="get" class="row g-3 float-left mr-2">
                    <div class="col-auto">
                        @*<label>Search</label>*@
                        <input class="form-control" asp-for="SearchText" type="text" id="search" name="search" value="@Model.SearchText" placeholder="@L["input_placeholder_search"]" />

                    </div>
                    <div class="col-auto">
                        <button type="submit" class="btn btn-primary">@L["btn_search"]</button>
                    </div>
                </form>
                <a class="btn btn-outline-primary ml-2" asp-page="ApiResource/Create" asp-route-ReturnUrl="@thisUrl">@L["btn_add_idRes"]</a>
            </div>

            @*列表在这儿*@
            <div class="mt-3">
                <table class="table table-striped table-hover">
                    <thead>
                        <tr>
                            <th scope="col">@L["th_IdResourceName"]</th>
                            <th scope="col">@L["th_IdResourceDisplayName"]</th>
                            <th scope="col">@L["th_handle"]</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var idRes in Model.IdentityResource.Data)
                        {
                            <tr>
                                <td>@idRes.Name</td>
                                <td>@idRes.DisplayName</td>
                                <td>
                                    @*<a href="#" class="btn btn-secondary" title="@L["tips_usersInRole"]"><span class="oi oi-people"></span></a>*@
                                    <a asp-page="/Dashboard/IdentityResource/Configuration" asp-route-Id="@idRes.Id" class="btn btn-primary btn-sm" title="@L["btn_tips_configuration"]"><span class="oi oi-pencil"></span></a>
                                    @*<a asp-page="/Dashboard/Role/Delete" asp-route-ReturnUrl="@thisUrl" asp-route-roleName="@role.Name" asp-route-roleId="@role.Id" class="btn btn-danger ml-1" title="@L["btn_tips_del"]"><span class="oi oi-x"></span></a>*@
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
            </div>


            @*分页*@
            <nav>
                <ul class="pagination">
                    <li class="page-item @(Model.IdentityResource.PageIndex <= 1 ? "disabled" : string.Empty)">
                        <a class="page-link" href="?page=@(Model.IdentityResource.TotalPages -1)&search=@Model.SearchText" aria-label="Previous">
                            <span aria-hidden="true">&laquo;</span>
                        </a>
                    </li>
                    @if (Model.IdentityResource.TotalPages > 6)
                    {
                        //不能完全显示
                        <li class="page-item"><a class="page-link" href="?page=1">1</a></li>
                        <li class="page-item"><a class="page-link">··</a></li>
                        <li class="page-item"><a class="page-link" href="?page=@(Model.IdentityResource.TotalPages -1)&search=@Model.SearchText">@(Model.IdentityResource.TotalPages -1)</a></li>
                        <li class="page-item active"><a class="page-link" href="#">@(Model.IdentityResource.TotalPages)</a></li>
                        <li class="page-item"><a class="page-link" href="?page=@(Model.IdentityResource.TotalPages + 1)&search=@Model.SearchText">@(Model.IdentityResource.TotalPages + 1)</a></li>
                        <li class="page-item"><a class="page-link">··</a></li>
                        <li class="page-item"><a class="page-link" href="?page=@(Model.IdentityResource.TotalPages)&search=@Model.SearchText">@Model.IdentityResource.TotalPages</a></li>
                    }
                    else
                    {
                        //完全显示
                        for (int i = 1; i <= Model.IdentityResource.TotalPages; i++)
                        {
                            <li class="page-item @(Model.IdentityResource.PageIndex == i ? "active" : string.Empty)"><a class="page-link" href="@(Model.IdentityResource.PageIndex == i ? "#" : $"?page={i}&search={Model.SearchText}")">@i</a></li>
                        }
                    }

                    <li class="page-item @(Model.IdentityResource.PageIndex == Model.IdentityResource.TotalPages ? "disabled" : string.Empty)">
                        <a class="page-link" href="#" aria-label="Next">
                            <span aria-hidden="true">&raquo;</span>
                        </a>
                    </li>

                </ul>
            </nav>

        </div>
    </div>
</div>

<environment include="Development">
    @*开发模式下的JS引用之类的*@
    <script src="~/lib/clipboardjs/clipboard.js"></script>
</environment>
<environment exclude="Development">
    @*发布模式下的js引用之类的*@
    <script src="~/lib/clipboardjs/clipboard.min.js"></script>
</environment>


<script>
    new ClipboardJS(".btn");
</script>